package com.smarthome.core.workingmonitor.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShEquipmentCommLogService;
import com.smarthome.common.tools.EnumUtil;
import com.smarthome.core.dictionary.DeviceTypeService;
import com.smarthome.core.workingmonitor.EquipmentCommLogService;
import com.smarthome.domain.bean.ShEquipmentCommLog;
import com.smarthome.domain.enums.EquipmentTypeEnum;
import com.smarthome.domain.enums.ResultEnum;
import com.smarthome.domain.ipc.req.IpcLogRecordRequest;
import com.smarthome.domain.vo.boss.Combobox;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Service("equipmentCommLogService")
public class EquipmentCommLogServiceImpl implements EquipmentCommLogService {

    protected static Logger LOGGER;

    @Resource
    private ShEquipmentCommLogService shEquipmentCommLogService;

    @Resource
    private DeviceTypeService deviceTypeService;

    @Override
    public DataGrid dataGrid(ShEquipmentCommLog equipmentCommLog, PageHelper page) {
        return shEquipmentCommLogService.queryShEquipmentCommLogs(equipmentCommLog, page);
    }

    @Override
    public List<Combobox> equipmentTypeId(boolean flag) {
        List<Combobox> result = new ArrayList<>();
        if (flag) {
            Combobox combobox = new Combobox();
            combobox.setValue("");
            combobox.setText("--请选择--");
            combobox.setSelected(true);
            result.add(combobox);
        }
        EquipmentTypeEnum[] equipmentTypes =  EquipmentTypeEnum.values();
        // 转combobox
        for (EquipmentTypeEnum type : equipmentTypes) {
            Combobox combobox = new Combobox();
            combobox.setValue(type.getCode());
            combobox.setText(type.getName());
            result.add(combobox);
        }
        return result;
    }

    @Override
    public List<Combobox> results(boolean flag) {
        List<Combobox> result = new ArrayList<>();
        if (flag) {
            Combobox combobox = new Combobox();
            combobox.setValue("");
            combobox.setText("--请选择--");
            combobox.setSelected(true);
            result.add(combobox);
        }
        List<ResultEnum> resultEnum = EnumUtil.getEnumList(ResultEnum.class);
        for (ResultEnum results : resultEnum) {
            Combobox combobox = new Combobox();
            combobox.setValue(String.valueOf(results.getCode()));
            combobox.setText(results.getName());
            result.add(combobox);
        }
        return result;
    }

    @Override
    public void saveLog(ShEquipmentCommLog equipmentCommLog) {
        shEquipmentCommLogService.record(equipmentCommLog);
    }

}
